﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class PointExchange
    {
        private readonly Chain.IDAL.PointExchange dal = new Chain.IDAL.PointExchange();

        public bool Add(List<Chain.Model.PointExchange> list)
        {
            return this.dal.Add(list);
        }

        public int Add(Chain.Model.PointExchange model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.PointExchange> DataTableToList(DataTable dt)
        {
            List<Chain.Model.PointExchange> list = new List<Chain.Model.PointExchange>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.PointExchange item = new Chain.Model.PointExchange();
                    if ((dt.Rows[i]["ExchangeID"] != null) && (dt.Rows[i]["ExchangeID"].ToString() != ""))
                    {
                        item.ExchangeID = int.Parse(dt.Rows[i]["ExchangeID"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeMemID"] != null) && (dt.Rows[i]["ExchangeMemID"].ToString() != ""))
                    {
                        item.ExchangeMemID = int.Parse(dt.Rows[i]["ExchangeMemID"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeGiftID"] != null) && (dt.Rows[i]["ExchangeGiftID"].ToString() != ""))
                    {
                        item.ExchangeGiftID = int.Parse(dt.Rows[i]["ExchangeGiftID"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeNumber"] != null) && (dt.Rows[i]["ExchangeNumber"].ToString() != ""))
                    {
                        item.ExchangeNumber = int.Parse(dt.Rows[i]["ExchangeNumber"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeTotalPoint"] != null) && (dt.Rows[i]["ExchangeTotalPoint"].ToString() != ""))
                    {
                        item.ExchangeTotalPoint = int.Parse(dt.Rows[i]["ExchangeTotalPoint"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeShopID"] != null) && (dt.Rows[i]["ExchangeShopID"].ToString() != ""))
                    {
                        item.ExchangeShopID = int.Parse(dt.Rows[i]["ExchangeShopID"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeTime"] != null) && (dt.Rows[i]["ExchangeTime"].ToString() != ""))
                    {
                        item.ExchangeTime = DateTime.Parse(dt.Rows[i]["ExchangeTime"].ToString());
                    }
                    if ((dt.Rows[i]["ExchangeUserID"] != null) && (dt.Rows[i]["ExchangeUserID"].ToString() != ""))
                    {
                        item.ExchangeUserID = int.Parse(dt.Rows[i]["ExchangeUserID"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ExchangeID)
        {
            return this.dal.Delete(ExchangeID);
        }

        public bool DeleteList(string ExchangeIDlist)
        {
            return this.dal.DeleteList(ExchangeIDlist);
        }

        public bool Exists(int ExchangeID)
        {
            return this.dal.Exists(ExchangeID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.PointExchange GetModel(int ExchangeID)
        {
            return this.dal.GetModel(ExchangeID);
        }

        public List<Chain.Model.PointExchange> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.PointExchange model)
        {
            return this.dal.Update(model);
        }
    }
}

